/* Project: POPS
 * CS 279, Vanderbilt University
 * by: Igor I. Ges, Michael S. Parrish, Mark E. Sakauye
 *
 *  This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.popsDB.java.example;

import java.math.*;
import java.util.Date;
import java.util.Collection;
import com.popsDB.java.dao.CustomerorderhistoryDao;
import com.popsDB.java.dto.Customerorderhistory;
import com.popsDB.java.exceptions.CustomerorderhistoryDaoException;
import com.popsDB.java.factory.CustomerorderhistoryDaoFactory;

public class CustomerOrderhistoryTests
{
	public static void main(String[] arg) throws Exception
	{
		// Uncomment one of the lines below to test the generated code

		findAll();
		findByCustomers(1);
		findWhereCustomerOrderHistoryIDEquals(2);
	}

	public static void findAll()
	{
		try {
			CustomerorderhistoryDao _dao = getCustomerorderhistoryDao();
			Customerorderhistory _result[] = _dao.findAll();
			int _test[] = new int[15];

			System.out.println("**** Test Find All Order History ****");
			for (int i = 0; i < 15; i++) {
				_test[i] = i+1;
			}

			if (_test.length != _result.length) {
				System.out.println("FAILED\n");
			}
			else {
				int count = 0;
				for (int i=0; i<_result.length; i++ ) {
					if (_result[i].getCustomerOrderHistoryID() != _test[i]) {
						count = count + 1;
					}
				}
				if (count != 0) {
					System.out.println("FAILED\n");
				}
				else {
					System.out.println("PASSED\n");
				}
			}

		}
		catch (Exception _e) {
			_e.printStackTrace();
		}

	}

	public static void findByCustomers(int customerID)
	{
		try {
			CustomerorderhistoryDao _dao = getCustomerorderhistoryDao();
			Customerorderhistory _result[] = _dao.findByCustomers(customerID);

			System.out.println("***** Test Find By Customer ID = " + customerID 
					+ " *****");
			int count = 0;
			for (int i = 0; i < _result.length; i++) {
				if (_result[i].getCustomerID() != customerID) {
					count = count + 1;
				}
			}

			if (count != 0) {
				System.out.println("FAILED\n");
			}
			else {
				System.out.println("PASSED\n");
			}

		}
		catch (Exception _e) {
			_e.printStackTrace();
		}

	}

	public static void findWhereCustomerOrderHistoryIDEquals(int customerOrderHistoryID)
	{
		try {
			CustomerorderhistoryDao _dao = getCustomerorderhistoryDao();
			Customerorderhistory _result[] = _dao.findWhereCustomerOrderHistoryIDEquals(customerOrderHistoryID);

			System.out.println("***** Test Find Where Customer Order History ID = 2");
			int count = 0;
			for (int i = 0; i < _result.length; i++) {
				if (_result[i].getCustomerOrderHistoryID() != customerOrderHistoryID) {
					count = count + 1;
				}
			}
			if (count == 0) {
				System.out.println("PASSED\n");
			}
			else {
				System.out.println("FAILED\n");
			}

		}
		catch (Exception _e) {
			_e.printStackTrace();
		}

	}

	public static CustomerorderhistoryDao getCustomerorderhistoryDao()
	{
		return CustomerorderhistoryDaoFactory.create();
	}

}
